package com.itheima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.entity.Article;
import com.itheima.mapper.ArticleMapper;
import com.itheima.service.IArticleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.vo.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yancy
 * @since 2024-03-07
 */
@Service
public class ArticleServiceImpl extends ServiceImpl<ArticleMapper, Article> implements IArticleService {

    @Autowired
    private ArticleMapper articleMapper;

    @Override
    public PageBean<Article> pageList(Integer pageNum, Integer pageSize, Integer categoryId, String state) {
        PageBean<Article> pageBean = new PageBean<>();
        PageHelper.startPage(pageNum,pageSize);
        List<Article> articles = articleMapper.list(1, categoryId, state);
        Page<Article> articlePage = (Page<Article>) articles;
        pageBean.setTotal(articlePage.getTotal());
        pageBean.setItems(articlePage.getResult());
        return pageBean;
    }
}
